package net.dodoman.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

	private DateUtils() {

	}

	/**
	 * 获取当前日期周一
	 * 
	 * @param date
	 * @return
	 */
	public static String getMonday(int year, int month, int day) {
		Calendar c = Calendar.getInstance();
		// c.setTime(date);
		c.set(year, month, day);
		c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
		return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
	}

	/**
	 * 获取当前日期周一
	 * 
	 * @param date
	 * @return
	 */
	public static String getMonday(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
		return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
	}

	/**
	 * 获取该日期在一年中的第几个星期
	 * 
	 * @param year
	 * @param month
	 * @param day
	 * @return
	 */
	public static int getWeekOfYear(int year, int month, int day) {
		Calendar c = Calendar.getInstance();
		c.set(year, month, day);
		return c.get(Calendar.WEEK_OF_YEAR);
	}

	/**
	 * 获取该日期一周后日期或几周后日期
	 * 
	 * @param year
	 * @param month
	 * @param day
	 * @return
	 */
	public static String getPreOrNextWeek(int year, int month, int day, int num) {
		Calendar c = Calendar.getInstance();
		c.set(year, month, day);
		c.add(Calendar.WEEK_OF_YEAR, num);
		return new SimpleDateFormat("yyyy-MM-dd").format(c.getTime());
	}

	/**
	 * 根据给定日期格式返回年月日
	 * 
	 * @param ymd
	 *            格式为"年-月-日"
	 * @return 数组第一个为年,第二个为月,第三个位日
	 */
	public static String[] getYmd(String ymd) {
		return ymd.split("-");
	}

}
